<?php

namespace support\login;

use app\services\SmsService;
use app\services\UserService;
use plugin\admin\app\common\Util;
use plugin\admin\app\model\User;

class GeneralLogin implements LoginContract
{

    public function check($data)
    {
        if (!$data['mobile']) {
            throw new \Exception('手机号不能为空');
        }

        $user = User::where('mobile', $data['mobile'])->first();

        if (!$user) {
            throw new \Exception('未注册的手机号');
        }

        if (!Util::passwordVerify($data['password'], strval($user['password']))) {
            throw new \Exception('不正确的登录密码');
        }

        return UserService::profile($user['id']);
    }
}